package com.dd.cloud.common.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

/**
 * 登录信息，解析JWT中登录携带的信息
 *
 * @author zk
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class LoginInfo {
    /**
     * 账号ID
     * 会员id取learn_member的id,
     * 会员单位取company_user的id,
     * 委员会取learn_admin_user的id
     * 学会取admin_user的id
     */
    private Integer id;

    /**
     * 药房id
     */
    private Integer pharId;

    /**
     * 机构id, 系统管理员登录此为0
     */
    private Integer mechanId;

    /**
     * 权限id
     */
    private Integer roleId;

    /**
     * 1医生 2机构管理员 3系统管理员
     */
    private Integer type;

    /**
     * 登录者名字
     */
    private String name;

    /**
     * 第三方登录id,微信为unionid
     */
    private String platId;

    /**
     * 过期时间
     */
    private Date expirationDate;

    /**
     * 登录的客户端唯一标识, userAgent+ip地址 用作浏览器指纹 防止截取cookie在其他客户端登录,
     * 在同一个网段下,客户端与所在的电脑版本与基础配资完全一致的情况下这个值会一样
     */
    private String userAgent;

    /**
     * 1医生 2机构管理员 3系统管理员 4药房 5代理商 6患者 7开放平台
     */
    public static class UserType {
        public final static int DOCTOR = 1;
        public final static int MECHAN = 2;
        public final static int ADMIN = 3;
        public final static int PHAR = 4;
        public final static int AGENT = 5;
        public final static int PATIENT = 6;
        public final static int OPEN = 7;
    }

    /**
     * 手动登录 药房端
     *
     * @param id
     * @param type
     */
    public LoginInfo(Integer id, Integer type, String name, Integer pharId, Integer roleId, String userAgent) {
        this.id = id;
        this.type = type;
        this.pharId = pharId;
        this.name = name;
        this.roleId = roleId;
        this.platId = null;
        this.userAgent = userAgent;
    }

    /**
     * 管理员登录
     *
     * @param id
     * @param type
     */
    public LoginInfo(Integer id, Integer mechanId, Integer type, String name, Integer roleId, String userAgent) {
        this.id = id;
        this.type = type;
        this.mechanId = mechanId;
        this.name = name;
        this.roleId = roleId;
        this.platId = null;
        this.userAgent = userAgent;
    }

    /**
     * 手动登录
     *
     * @param id
     * @param type
     */
    public LoginInfo(Integer id, Integer mechanId, Integer type, String name, String userAgent) {
        this.id = id;
        this.type = type;
        this.mechanId = mechanId;
        this.name = name;
        this.platId = null;
        this.userAgent = userAgent;
    }

    /**
     * 第三方登录
     *
     * @param id
     * @param type
     * @param platId
     */
    public LoginInfo(Integer id, Integer mechanId, Integer type, String name, String platId, String userAgent) {
        this.id = id;
        this.mechanId = mechanId;
        this.type = type;
        this.name = name;
        this.platId = platId;
        this.userAgent = userAgent;
    }
}
